<?php require_once 'header.php'; ?>
<script>
$("title").html("登陆");
</script>

<?php 

if ((!empty($_POST['email']))&&(!empty($_POST['password']))){
    require_once 'connect.php';
    $class=$_POST['class'];
    $className="";
    switch ($class) {
      case 1:
      $className="administrations";
        break;
      case 2:
      $className="teachers";
       break;
      case 3:
      $className="students";
        break;
      default:
        
        break;
    }
    $query="select * from ".$className." where email='".$_POST['email']."' and password='".$_POST['password']."'";
    $result=$mysql->query($query);
    if ($result) {
      $row=$result->fetch_assoc();
      session_start();
      $_SESSION['status']=$class;
      $_SESSION['id']=$row['id'];
      $_SESSION['name']=$row['name'];
      echo "<script>window.location.href='./';</script>";
    }else{
      echo "登陆失败！";
    }
    $mysql->close();
  }

 ?>
<div class="container">

      <form class="form-signin" action ="./signin.php" method="post">
        <h2 class="form-signin-heading">用户登录</h2>
        <select class="form-control" name="class">
          <option value="1">教务管理人员</option>
          <option value="2">教师</option>
          <option value="3">学生</option>
          </select>
        
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" id="inputEmail" class="form-control" placeholder="Email address" name="email" required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="Password" name="password" required>
        <div class="checkbox">
          <label>
            <input type="checkbox" value="remember-me"> 记住我
          </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit">登陆</button>
      </form>
      <br>
      <?php require_once 'addMail.php'; ?>
      <br>
      <a href="login.php" class="btn btn-lg btn-default btn-block" role="button">注册</a>
    </div> <!-- /container -->


<?php require_once 'footer.php'; ?>
